package com.hanlink.dsp.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.edge.pbxdsp.R;
import com.qztech.utils.YzDebug;

/**
 * Copyright (C), 深圳市东乘电子科技有限公司
 * Carate By YangZhong
 */
public class XOverFrequencyView extends View {
    private float textSize;
    private Paint mPaint;
    private String textArr[];
    private float offset = 20;
    private float mTextWidths[];
    private float mStep = 0;
    public XOverFrequencyView(Context context) {
        super(context);
        init(context);
    }

    public XOverFrequencyView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public XOverFrequencyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);

    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mStep = w/textArr.length;

    }


    private void init(Context context){
        textArr = new String[]{
                "20","100","320","500","750","1.25K","3K","6k","10k","14k","22k",
        };
        textSize = 12;
        mPaint = new Paint();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            mPaint.setColor(context.getColor(com.hanlink.res.R.color.common_tab_bg));
        }
        mPaint.setTextSize(textSize*context.getResources().getDisplayMetrics().density);
        mTextWidths = new float[textArr.length];
        calTextWidth();
    }
    private  void calTextWidth(){
        for (int i = 0, len = textArr.length; i < len; i++) {
            mTextWidths[i] = mPaint.measureText(textArr[i]);
        }
    }
    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        float left = 0;
        for (int i = 0, len = textArr.length; i < len; i++) {
            canvas.drawText(textArr[i],left+(mStep - mTextWidths[i])/2f,getHeight(),mPaint);
            left += mStep;
        }
    }
}
